/**
 * Created by leezhenbo on 15/5/21.
 */
package {
import events.NavigationEvent;

import screens.InGame;

import screens.Welcome;

import starling.display.Sprite;
import starling.events.Event;


public class Game extends Sprite{
    /**
     * 欢迎界面
     */
    private var welcomeScreen:Welcome;

    /**
     * 主界面
     */
    private var screenInGame:InGame;

    public function Game() {
        this.addEventListener(Event.ADDED_TO_STAGE,onAddedToStageHandler);
    }

    protected function onAddedToStageHandler(event:Event):void{
        this.removeEventListener(Event.ADDED_TO_STAGE,onAddedToStageHandler);

        this.addEventListener(NavigationEvent.CHANGE_SCREEN,onChangeScreen);

        screenInGame = new InGame();
        screenInGame.disposeTemporaily();
        this.addChild(screenInGame);

        if(!welcomeScreen){
            welcomeScreen = new Welcome();
            this.addChild(welcomeScreen);
        }

        welcomeScreen.initialize();
    }

    private function onChangeScreen(event:NavigationEvent):void{
        switch (event.params.id){
            case 'play':
                welcomeScreen.disposeTemporaily();
                screenInGame.initialize();
                break;
            default :
                break;
        }
    }
}
}
